﻿using System;
using System.Collections.Generic;
using System.Linq;
using System.Text;
using System.Threading.Tasks;
using QLCHBANGIAY.DATA;

namespace QLCHBANGIAY.BUSINESS
{
    public class CategoryServices
    {

        private static CategoryControler db = new CategoryControler();
        #region[Category_GetById]
        public static List<Category> Category_GetById(string Id)
        {
            return db.Category_GetById(Id);
        }
        #endregion
        #region[Category_GetByTop]
        public static List<Category> Category_GetByTop(string Top, string Where, string Order)
        {
            return db.Category_GetByTop(Top, Where, Order);
        }
        #endregion
        #region[Category_GetByIndex]
        public static List<Category> Cate_Products_GetByIndex(string Index, string Lang)
        {
            List<Category> list = new List<Category>();
            list = Category_GetByAll(Lang);
            return list.FindAll(delegate(Category obj)
            {
                return obj.Active == "1" && obj.Index == Index;
            });
        }
        #endregion
        #region[Category_GetByAll]
        public static List<Category> Category_GetByAll(string Lang)
        {
            return db.Category_GetByAll(Lang);
        }
        #endregion
        //#region[Category_GetByAll]
        //public static List<Data.Category> Category_GetByCategory()
        //{
        //    return db.Category_GetByCategory();
        //}
        //#endregion
        #region[Category_GetByLevel]
        public static List<Category> Category_GetByLevel(string Level, string Lang)
        {
            return Category_GetByLevel(Level, Lang, 0);
        }
        public static List<Category> Category_GetByLevel(string Level, string Lang, string Active)
        {
            List<Category> list = new List<Category>();
            list = Category_GetByLevel(Level, Lang);
            return list.FindAll(delegate(Category obj)
            {
                return obj.Active == Active;
            });
        }
        public static List<Category> Category_GetByLevel(string Level, string Lang, int LevelLength)
        {
            return db.Category_GetByLevel(Level, Lang, LevelLength);
        }
        public static List<Category> Category_GetByLevel(string Level, string Lang, int LevelLength, string Active)
        {
            List<Category> list = new List<Category>();
            list = Category_GetByLevel(Level, Lang, LevelLength);
            return list.FindAll(delegate(Category obj)
            {
                return obj.Active == Active;
            });
        }
        #endregion
        #region[Category_Paging]
        public static List<Category> Category_Paging(string CurentPage, string PageSize, string Lang)
        {
            return db.Category_Paging(CurentPage, PageSize, Lang);
        }
        #endregion
        #region[Category_Insert]
        public static bool Category_Insert(Category data)
        {
            return db.Category_Insert(data);
        }
        #endregion
        #region[Category_Update]
        public static bool Category_Update(Category data)
        {
            return db.Category_Update(data);
        }
        #endregion
        #region[Category_Update_Ord]
        public static bool Category_Update_Ord(Category data)
        {
            return db.Category_Update_Ord(data);
        }
        #endregion
        #region[Category_Delete]
        public static bool Category_Delete(string Id)
        {
            return db.Category_Delete(Id);
        }
        #endregion
        #region[Category_LoadNavigation]
        public static string Category_LoadNavigation(string strLevel, string Lang)
        {
            string strReturn = string.Empty;
            for (int i = 1; i <= strLevel.Length / 5; i++)
            {
                string strTempLevel = strLevel.Substring(0, i * 5);
                string strSelect = strLevel.Equals(strTempLevel) ? " class=\"last\"" : string.Empty;
                List<DATA.Category> list = BUSINESS.CategoryServices.Category_GetByLevel(strTempLevel, Lang, i * 5);
                if (list.Count > 0)
                {
                    strReturn += string.Format("<img src=\"/images/icon_root.gif\" align=\"baseline\"> <a" + strSelect + " href=\"/products/{0}/{1}.aspx\">{2}</a> ", list[0].Id, list[0].Tag, list[0].Name);
                }
            }
            return strReturn;
        }
        #endregion

    }
}
